import pygp

##a = pygp.Node('a', [], None)#leaf
##b = pygp.Node('b', [], None)#leaf
##f = pygp.Node('f', [], None)
##
##c = pygp.Node('c', [a], None)
##d = pygp.Node('d', [b, c], None)
##e = pygp.Node('e', [d, f], None)
##
####print d.GetHeightNode()
##
###add new node into a
##g = pygp.Node('g', [], None)
##a.children.append(g)
####print d.GetHeightNode()
##
##
###Tree 2
##n1 = pygp.Node('g', [], None)
##n2 = pygp.Node('a', [n1], None)
##n3 = pygp.Node('c', [n2], None)
##temp = pygp.Node('l', [], None)
##n4 = pygp.Node('b', [temp], None)
##n5 = pygp.Node('d', [n4, n3], None)
###test Node Cmp
####print d.NodeCmp(n5)
##
##print 'size: ', pygp.GetSizeNode(e, True)
##print 'branch: ', pygp.GetAVGNode(e)

term = pygp.Term()
term.AddTerm("ADD", 2)
term.AddTerm("SUB", 2)
term.AddTerm("DIV", 2)
term.AddTerm("MUL", 2)
term.AddTerm("SIN", 1)
term.AddTerm("COS", 1)
term.AddTerm("EP", 1)
term.AddTerm("X", 0)

gp = pygp.Genetic(term)
for i in range(250):
    tree = gp.GrowthTreeGen(15)
##tree = gp.FullTreeGen(5)
print tree.ToString()
####a= tree.FindNode(4)
##a = tree[4]
##print "Subtree 4th: ", a[0].ToString()
##print "Parent: ", a[1].ToString()
##print "Size: ", tree.GetSize(False)
##print "AVG: ", tree.GetAVGNode()

##gp.RampedInit(5, 0.1)

##print 'tree 1: ', gp.oldpop[0].chrom.ToString()
##print 'tree 2: ', gp.oldpop[1].chrom.ToString()
##cross = gp.Crossover(gp.oldpop[0], gp.oldpop[1])
##
##if(cross):
##    print 'child 1: ', cross[0].chrom.ToString()
##    print 'child 2: ', cross[1].chrom.ToString()

##mutation = gp.Mutation(gp.oldpop[0], 5, 'growth')
##mutation = gp.Mutation(tree, 5, 'growth')

##if(mutation):
##    print 'Mutation: ', mutation.chrom.ToString()
##
##for individual in gp.oldpop:
##    print individual.chrom.ToString()
